Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waypoint tracking improvements #10278

Merged
merged 10 commits into from
Sep 4, 2024

Conversation

breadoven
Copy link
Collaborator

Changes the method used for waypoint tracking to try and fix issues with faster planes which causes instability. Now uses cross track error rate of change to fine tune heading adjustments giving more active control.

Testing on HITL with the flying wing shows the previous instability is gone together with better turn performance with less overshoot. Flight testing on a conventional plane also appears to perform better. Needs more testing though with other plane types to know if it's better overall than the current method.

@b14ckyy
Copy link
Collaborator

b14ckyy commented Aug 4, 2024

So glad to see improvements here. Thanks a lot!

@b14ckyy
Copy link
Collaborator

b14ckyy commented Aug 4, 2024

Just tested it in HIT myself. With these tweaks I was able to go down to 3 for Tracking accuracy and with very sharp turns or 180° turns its perfect. But it still seems to struggle with turn smoothing "cut" at 90° turns. The bank starts a tad too late and is then adjusting slightly too soft. Could bank much harder as the config allows it. If this can be optimized as well this would be Industrial grade WP tracking for Aerial surveys :D For turn smoothing on to do the outside turn, its the same.

First half of the video is with Accuracy 6, second half after the cut is on 3 https://www.youtube.com/watch?v=xUHpfCK9mVM

image
image
image

@breadoven
Copy link
Collaborator Author

breadoven commented Aug 5, 2024

I didn't do anything about the turn smoothing issue. Not sure what the answer is there. As you say, the control is there to achieve what you want but getting it to do it consistently isn't easy. You could probably fiddle something to start the turn earlier but then you'd find it was over cutting the corner when the wind changed direction. I might try resetting the position controller to see if that improves things (resets the PID influence of the previous straight line flight behaviour). The main problem with the turns is it uses the circular loiter method but only for up to half a turn which isn't long enough to establish the turn correctly. I've always noticed loiter mode usually takes at least 1 full turn before it settles down into a turn with a consistent radius, the initial radius tends to be wider before closing down as the turn continues.

@b14ckyy
Copy link
Collaborator

b14ckyy commented Aug 5, 2024

Fair enough. Its a different beast to tame.
But the tracking works great now. Noticeable improvement.

@Jetrell
Copy link

Jetrell commented Aug 6, 2024

The bank starts a tad too late and is then adjusting slightly too soft. Could bank much harder as the config allows it

My observation with elevon controlled planes is always like this.

But if I run the same mission with any of my tractor twins or conventional rudder airframe. With nav_use_fw_yaw_control = ON using a compass.. They turn and track perfectly, even in crosswinds over 25km/h..
The difference in that case, is half the turning and track alignment is done by Yaw control, whether by rudder or differential thrust, not just banking.
But if the fixedwing.c has bank angle as the primary means to turn the airplane. The control response may be limited to allow yaw to do some of the work if the plane has the hardware..
On the tractor twins, I have to manage nav_fw_bank_angle , nav_fw_control_smoothness with differential thrust tuning. Because yaw becomes down pitch in a tight bank turn, which can over-do it when turning from a headwind, to a crosswind.

@breadoven
Copy link
Collaborator Author

Actually I forgot that CUT turn smoothing doesn't use the circular loiter code it simply switches to the next waypoint at some distance before reaching the current waypoint. The distance is a function of the turn angle and circular loiter radius setting so it helps if the loiter radius is set correctly. The path it flies to the next course line will be based on the course tracking alignment code ... although this only happens when it's within 90 degrees of the course line bearing.

@b14ckyy
Copy link
Collaborator

b14ckyy commented Aug 6, 2024

Actually lets better check that part only with real world flights. HITL is nice and all but does not really represent a real flight in terms of nav precision with the slow sensor rates and the wonky small craft physics.

I am planning on a long test session next weekend so I can put this snapshot on my altus and try it out.

@breadoven
Copy link
Collaborator Author

breadoven commented Aug 8, 2024

Made some improvements, the main one being increasing the update frequency for cross track error rate from 2 to 10 Hz which seems to have made a big difference. This now seems to work as originally intended based on HITL testing, tracking back to the course line quickly after turns with little or no overshoot.

Still loses accuracy at very high speeds (>120 kph or so) but that's always going to be an issue with the relatively sluggish response of fixed wing roll control. Conventional aircraft should be better with a rudder to help.

@b14ckyy
Copy link
Collaborator

b14ckyy commented Aug 8, 2024

Nice one. Will test in HITL later and flash to my Altus for testing on the weekend.

@b14ckyy
Copy link
Collaborator

b14ckyy commented Aug 10, 2024

Tested in real flight just now. Can upload video later.
Looks much better. Can go down to level 1 with the precision and still nice good tracking. Only overshoots when turning into strong downwind but that's still a struggle for the general navigation system.

Looks good to me for merging.

@breadoven
Copy link
Collaborator Author

breadoven commented Aug 10, 2024

I made a few more minor tweaks mainly to reduce a potential control oscillation you get as you approach the course line. Other than that it's definitely better than the current method. I did notice though that changing the Nav Position PIDS also makes a significant difference to how it behaves at the turns so it's a bit of a tuning nightmare really although one benefit of this improved method is it seems to be less sensitive to the nav_fw_wp_tracking_accuracy setting.

@b14ckyy
Copy link
Collaborator

b14ckyy commented Aug 10, 2024

I think whoever makes things that rely on precise path tracking should know how to fine tune the plane.
Additionally I noticed that I accidently had the Compass turned on after the last 8.0 flash. It was calibrated once but it sits right on the battery. So it also might have caused a bit of deviation in that wind before INAV detects the heading/course error.

Could not do another test with no compass as I failed the launch and cracked my tail boom mount :D Will try again tomorrow. If you have any further changes, commit them and I will add it to the test.

@breadoven
Copy link
Collaborator Author

I've tried a different method to try and improve this some more which seems to perform even better than the current changes. It even works at speeds of 180 km/h according to HITL. Oddly though it's not so good at lower speeds but this might just need some sort of speed related adjustment adding. It's simpler than the current method with less fiddle factors so definitely better if the low speed can be improved.

@breadoven
Copy link
Collaborator Author

New method seems a big improvement. Now working at all speeds and even managed to change nav_fw_wp_tracking_accuracy to an ON/OFF setting, no more tuning required. Needs flight testing though, only HITL so far.

@breadoven breadoven added this to the 8.0 milestone Aug 19, 2024
@b14ckyy
Copy link
Collaborator

b14ckyy commented Aug 19, 2024

Sounds good. I smoked my Altus yesterday.... Hope I can get more tests in the coming weekend

@breadoven
Copy link
Collaborator Author

Made some final changes here. Decided the cut turn addition didn't really work so removed it. Also changed the nav_fw_wp_tracking_accuracy setting back to numerical 0 to 10 except it now sets the tracking deadband. This was fixed at 2m from the waypoint course line but it makes sense to have this as a setting so you can decide how accurately you want it to track without excessive tracking corrections occurring.

@Jetrell
Copy link

Jetrell commented Aug 27, 2024

This was with the last commit. The plane is elevon controlled.
This specific plane tracked significantly better than I'd ever seen it do so before in a mission.
And it wasn't far short of how well the tractor twins follow a mission, with the present tracking method.
But it absolutely requires the heading controller to be enabled nav_fw_yaw_control = ON . Otherwise it tracked as bad as ever.. And this was only with a 2 - 7km/h winds, in both cases.
Although, originally this plane used to track rather aweful, even with the heading controller enabled with the present tracking method.

WITHOUT heading controller
Without nav_use_fw_yaw_control

WITH heading controller
With nav_use_fw_yaw_control

These are all setting changes I made to the elevon plane, to help it respond faster and track better. Of which the heading controller helped the most.
nav_fw_heading_p = 70
nav_fw_pos_hdg_p = 45
nav_fw_pos_hdg_i = 5
nav_fw_pos_hdg_d = 6
nav_use_fw_yaw_control = ON
nav_wp_radius = 500
nav_fw_wp_tracking_accuracy = 1
nav_fw_wp_tracking_max_angle = 45
nav_fw_wp_turn_smoothing = ON-CUT
nav_fw_bank_angle = 45
nav_fw_control_smoothness = 6

The average speed in the mission was 80km/h. And it has a compass.

And for a comparison. The same mission was done at an earlier time with the present tracking method, using a tractor twin with differential thrust for yaw control.
I never tested it again with this PR, because I don't imagine it turning any tighter or tracking any better than it already does.
This particular mission was also done in a 20 - 25km/h winds.

TWIN with heading controller (old method)
Capture

@b14ckyy
Copy link
Collaborator

b14ckyy commented Aug 27, 2024

But it absolutely requires the heading controller to be enabled nav_fw_yaw_control = ON . Otherwise it tracked as bad as ever.. And this was only with a 2 - 7km/h winds, in both cases.

I Think we might need to look at the Preset profiles again for 8.0. I see no point in not having this ON by default. Does it have negative impacts on planes with no tail? It should only affect yaw mixes, right?

@Jetrell
Copy link

Jetrell commented Aug 27, 2024

I Think we might need to look at the Preset profiles again for 8.0. I see no point in not having this ON by default. Does it have negative impacts on planes with no tail? It should only affect yaw mixes, right?

Having the heading controller enabled for tractor twins, also makes a big improvement.. BUT if you increase the Yaw differential mixing higher that 0.5. It can snap out real bad. Especially if nav_fw_control_smoothness is set lower than 8. Meaning it requires a lot of smoothing.

But as for elevon controlled planes (flying wings). I agree. nav_use_fw_yaw_control would be better to have enabled by default with the PR.

@b14ckyy
Copy link
Collaborator

b14ckyy commented Aug 27, 2024

a 0.5 Yaw diff mix would be insane anyway. I find even 0.3 is way too high due to risk of flat spin on powerful setups. on the few twins I have I never go above 0.2, usually 0.1. Especially just to get some extra yaw stabilization against wiggle.

@breadoven
Copy link
Collaborator Author

I assume the plane used for the test @Jetrell had some sort of yaw control ? Hard to see how setting nav_fw_yaw_control = ON would help otherwise since as far as I can work out it just generates a yaw control output that doesn't appear to affect roll.

@Jetrell
Copy link

Jetrell commented Aug 28, 2024

I assume the plane used for the test had some sort of yaw control ? Hard to see how setting nav_fw_yaw_control = ON would help otherwise since as far as I can work out it just generates a yaw control output that doesn't appear to affect roll.

No not at all. The plane is a Dolphin.
My assumption, which I will have to put to the test. Is to turn off the mag on this model one day.
Being that the heading controller is on by default for Boats and Rovers, which I would assume are intended to use with a compass.

The last time I tested this plane with the heading controller enabled, was back in 6.0. And it flew as bad as the first mission image I posted... And when I tested it again yesterday with your commits. I assumed it would fly well without the heading controller.. But you seen the result above.
So I thought I better turn it on, just in case your changes were done with it enabled in the sim.
And it then tracked as seen in the second missions image.

But since I haven't flown this plane with nav_fw_yaw_control = ON since 6.0. Because of my disgust in how badly it tracked a mission... And this was added in 7.1 Yaw estimation .. Then maybe the mag with the heading controller is what is making most of the difference ? Because the tests I did for Shota back then was done with a twin. And it tracked rather badly before the changes he made. And that too with the heading controller enabled... But you see the last image I posted. Which happens to be the same twin from those tests back then too, which uses a compass as well.
But I didn't have heading controller enabled in those specific tests images I posted back then.. As can be seen by how much better that particular mission improved again to date, with those changes - The mag, The heading controller and the Yaw motor mixer.
#9387 (comment)

@breadoven
Copy link
Collaborator Author

breadoven commented Aug 28, 2024

The SIM testing had nav_use_fw_yaw_control set to OFF because HITL was just using the flying wing model.

I'm guessing setting nav_use_fw_yaw_control ON works because it generates an output for rcCommand[YAW] which feeds in to Turn Assistance which affects ROLL and PITCH control. When OFF rcCommand[YAW] is set to 0. Not really sure why you'd set it off in that case even for elevon craft unless sometimes it causes issues. Should probably be ON by default even for elevon craft given this although I tried it ON in HITL and it didn't appear to make much difference, but that's probably more a limitation of HITL perhaps.

@Jetrell
Copy link

Jetrell commented Aug 29, 2024

I'm guessing setting nav_use_fw_yaw_control ON works because it generates an output for rcCommand[YAW] which feeds in to Turn Assistance which affects ROLL and PITCH control.

I had considered that too, but I wasn't sure how that would make its turns more reactive.
However it would seem the turn angle isn't any better with the heading controller on, without a means to provide mechanical yaw control. But it tracks much straighter and gets back on course faster, so it gives the impression its turning better as well.
The wind estimator sensing xy yaw deviation from the projected heading, and applying correction with your recent fix of Turn Assist #10187 . seems like a reasonable explanation.

Plus I noticed when the plane was flying a leg slightly off the wind heading. I could see the roll trying much harder to hold the heading, than I'd encountered before. This was confirm by PID_ERROR[yaw] and likely due to me having nav_fw_wp_tracking_accuracy = 1. But this proved it is now trying much harder to track the course.

When it comes to the two heading controllers.. The first nav_fw_heading_p is only pushing to meet the target heading. But it has little means to prevent some overshoot.
While the second (nav_use_fw_yaw_control) nav_fw_pos_hdg being a full PID controller, makes more sense for the task.

Should probably be ON by default even for elevon craft

I would agree..
Although there are always going to be exceptions to the rule. Like in the case of an elevon aircraft that has rudder yaw control.. But in general, it would improve things for most users.
I think nav_use_fw_yaw_control was originally left OFF, because of the yaw i-term error accumulation issues most actively yaw controlled planes can suffer from... I find the easiest way to overcome this, is to use little or no i-term on yaw, depending on the means of control used. i.e Rudder, Differential thrust or Vectored thrust.

@breadoven
Copy link
Collaborator Author

breadoven commented Sep 1, 2024

I tested this the other day on a T tail and flying wing. T tail motor glider was very accurate, probably better than the current method which already worked OK. The flying wing, Sonic AR 900, behaved pretty well also, better than I expected. Flew better than before with little overshoot in the turns. This wing has a low KV motor and flies pretty slowly which makes it a bit wobbly at times but it still managed to track within 2m most of the time and that was in spite of having nav_use_fw_yaw_control set to OFF (forgot to turn it ON).

Altitude control also mainly seemed OK with no noticeable porpoising. That was with a nav_fw_alt_control_response set to 50 on the T-tail and 30 on the flying wing. I also changed the PID correction factors for P and I to 30 from 100 and it still flew OK with P = 30, I = 10, D = 10. I did however notice a problem with the linear climb used for WP missions which makes control at the target altitude sloppy and ineffective because the desired Z velocity ends up too small to be useable. Needs a fix.

@Jetrell
Copy link

Jetrell commented Sep 4, 2024

@breadoven Following up on what I mentioned last week.. I tested the Dolphin again with this build, with the heading controller enabled and the mag On and Off, with the same mission as earlier. But this day the temperature was only 4°C, with a very stiff 20km wind.
The results between the two were similar when tracking between waypoints.. But when the mag was enabled, the turns where a little earlier in each case.. With nav_fw_bank_angle being held for longer, while trying its best to hold the turn, when fighting the wind.
But I would say it did a good job, considering how miserable the conditions were, for both the plane and me.

The only things I could imagine that would make track/turning any better, but would be outside the scope of this PR. Would be earlier anticipation of the turn, based on virtual wind speed and direction. So the turn cut radius could be dynamic, based on the effect a tail or crosswind will have on the plane.
And the second would be a dynamic throttle control, based on bank angle. To assist the plane to pull through a tight turn, and also help to maintain altitude, in that turn.

@breadoven
Copy link
Collaborator Author

I think I'll merge this since it's definitely better than the existing method. I don't think it'll ever be perfect, there are just too many things that affect how well it behaves, numerous settings and of course the wind. But it's definitely better than not using it and if you want really good accuracy use a T tail with rudder control.

The last commit actually fixed a problem it's had for a while where the cross track error rate jumped about inconsistently which caused really bad roll control fluctuations in certain cases (mainly trackback where it's trying to follow closely spaced waypoints). Realised the waypoint distance wasn't being updated as frequently as the cross track error rate messing up the rate values. It now changes much more consistently which appears have improved things slightly.

@breadoven breadoven merged commit 376b35d into iNavFlight:master Sep 4, 2024
23 checks passed
@breadoven breadoven deleted the abo_wp_tracking_improvements branch September 12, 2024 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants